<?php
include_once '/PHPExcel/PHPExcel.php';
require_once '/PHPExcel/Reader/Excel2007.php';

require_once '/PHPExcel/Reader/Excel5.php';

include '/PHPExcel/IOFactory.php';

function getFormatExcel($filePath) {
	
	$PHPExcel = new PHPExcel ();
	$PHPReader = new PHPExcel_Reader_Excel2007 ();
	
	if (! $PHPReader->canRead ( $filePath )) {
		$PHPReader = new PHPExcel_Reader_Excel5 ();
		if (! $PHPReader->canRead ( $filePath )) {
			echo 'no Excel';
			return;
		}
	}
	
	$PHPExcel = $PHPReader->load ( $filePath );
	
	/**
	 * 读取excel文件中的第一个工作表
	 */
	$currentSheet = $PHPExcel->getSheet ( 0 );
	/**
	 * 取得最大的列号
	 */
	$allColumn = $currentSheet->getHighestColumn ();
	
	/**
	 * 取得一共有多少行
	 */
	$allRow = $currentSheet->getHighestRow ();
	// allRow = 877;
	
	$ExcelRowArray = array ();
	$rownum = 0;
	$rnum = 0;
	/**
	 * 从第二行开始输出，因为excel表中第一行为列名
	 */
	for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
		
		$Rowvalue = $playbillStr = null;
		/**
		 * 从第A列开始输出
		 */
		
		for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
			$val = '';
			$val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
			if ($val) {
				/**
				 * ord()将字符转为十进制数
				 */
				$ExcelRowArray [$currentRow - 2] [$currentColumn] = trim ( $val );
			
			}
		
		}
		
		$Rowvalue = &$ExcelRowArray [$currentRow - 2];
		
		$radiosarr = array ("name" => $Rowvalue ['B'], "channel" => $Rowvalue ['G'], "description" => addslashes ( $Rowvalue ['J'] ), "play_url" => $Rowvalue ['I'], 'check_state' => 1, "source" => 2, "create_time" => time (), "update_time" => time () );
		
		$qtid = $Rowvalue ['A'];
	
	}
}

function getExcel($filePath) {
	
	$PHPExcel = new PHPExcel ();
	$PHPReader = new PHPExcel_Reader_Excel2007 ();
	
	if (! $PHPReader->canRead ( $filePath )) {
		$PHPReader = new PHPExcel_Reader_Excel5 ();
		if (! $PHPReader->canRead ( $filePath )) {
			echo 'no Excel';
			return;
		}
	}
	
	$PHPExcel = $PHPReader->load ( $filePath );
	
	/**
	 * 读取excel文件中的第一个工作表
	 */
	$currentSheet = $PHPExcel->getSheet ( 0 );
	/**
	 * 取得最大的列号
	 */
	$allColumn = $currentSheet->getHighestColumn ();
	
	/**
	 * 取得一共有多少行
	 */
	$allRow = $currentSheet->getHighestRow ();
	// allRow = 877;
	
	$ExcelRowArray = array ();
	$rownum = 0;
	$rnum = 0;
	/**
	 * 从第二行开始输出，因为excel表中第一行为列名
	 */
	
	$returnArr;
	
	for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
		
		$Rowvalue = $playbillStr = null;
		/**
		 * 从第A列开始输出
		 */
		
		for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
			$val = '';
			$val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
			if ($val) {
				/**
				 * ord()将字符转为十进制数
				 */
				$ExcelRowArray [$currentRow - 2] [$currentColumn] = trim ( $val );
			
			}
		
		}
		
		$returnArr [] = &$ExcelRowArray [$currentRow - 2];
	
	}
	
	return $returnArr;
}